home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / MacApp Release 10 / MacApp Release 10 - HD Ready / Libraries / Framework / Sources / USubstitution.cp < prev    next >
Encoding:
Text File  |  1996-04-03  |  2.4 KB  |  88 lines  |  [TEXT/MPS ]

  1. //----------------------------------------------------------------------------------------
  2. // USubstitution.cp 
  3. // Copyright © 1988-96 by Apple Computer, Inc. All rights reserved.
  4. //----------------------------------------------------------------------------------------
  5.  
  6. #ifndef __USUBSTITUTION__
  7. #include "USubstitution.h"
  8. #endif
  9.  
  10. // MacApp
  11.  
  12. #ifndef __UASSOCIATION__
  13. #include "UAssociation.h"
  14. #endif
  15.  
  16. #ifndef __ULISTITERATOR__
  17. #include "UListIterator.h"
  18. #endif
  19.  
  20. //----------------------------------------------------------------------------------------
  21.  
  22. TAssociation* gParamTxt;                        // Used for text substitution 
  23.  
  24. //========================================================================================
  25. // GLOBAL Procedures
  26. //========================================================================================
  27. #undef Inherited
  28.  
  29. //----------------------------------------------------------------------------------------
  30. // InitUSubstitution: 
  31. //----------------------------------------------------------------------------------------
  32. #pragma segment DlgInit
  33.  
  34. void InitUSubstitution()
  35. {
  36.     if (!gParamTxt)
  37.     {
  38.         gParamTxt = new TAssociation;
  39.         gParamTxt->IAssociation();
  40.     }
  41. }
  42.  
  43. //----------------------------------------------------------------------------------------
  44. // MAParamText: 
  45. //----------------------------------------------------------------------------------------
  46. #pragma segment DlgRes
  47.  
  48. void MAParamText(const CStr255& keyStr,
  49.                  const CStr255& valueStr)
  50.  
  51. {
  52. #if qDebug
  53.     FailNonObject(gParamTxt);
  54. #endif
  55.     gParamTxt->InsertEntry(keyStr, valueStr);
  56. }
  57.  
  58. //----------------------------------------------------------------------------------------
  59. // MAReplaceText: 
  60. //----------------------------------------------------------------------------------------
  61. #pragma segment DlgRes
  62.  
  63. void MAReplaceText(CStr255& theText)
  64. {
  65. #if qDebug
  66.     FailNonObject(gParamTxt);
  67. #endif
  68.     CArrayIterator iter(gParamTxt->fEntries);
  69.     
  70.     for (ArrayIndex i = iter.FirstIndex(); iter.More(); i = iter.NextIndex())
  71.     {
  72.         TEntry* anEntry = (TEntry*)gParamTxt->fEntries->At(i);
  73.         short index;
  74.         
  75.         while ((index = theText.Pos(**(anEntry->fKey))) != 0)
  76.         {
  77.             theText.Delete(index, (**(anEntry->fKey)).Length());
  78.             if (theText.Length() + (**(anEntry->fValue)).Length() < sizeof(CStr255))
  79.                 theText.Insert(**(anEntry->fValue), index);
  80.         }
  81.     }
  82. }
  83.  
  84. //----------------------------------------------------------------------------------------
  85. // End of USubstitution.cp
  86.  
  87. #pragma segment Inline
  88.